home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell⁄THINK C / Window2.c < prev   
Encoding:
C/C++ Source or Header  |  1991-02-20  |  4.2 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:     CShell
  5. ** File:        window2.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "CShell.h"                /* Get the CShell includes/typedefs, etc.    */
  19. #include "CShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "CShell.protos"        /* Get the prototypes for CShell.            */
  21.  
  22. #ifndef __ERRORS__
  23. #include <Errors.h>
  24. #endif
  25.  
  26. #ifndef __FONTS__
  27. #include <Fonts.h>
  28. #endif
  29.  
  30. #ifndef __RESOURCES__
  31. #include <Resources.h>
  32. #endif
  33.  
  34. #ifndef __TEXTEDITCONTROL__
  35. #include "TextEditControl.h"
  36. #endif
  37.  
  38. #ifndef __TOOLUTILS__
  39. #include <ToolUtils.h>
  40. #endif
  41.  
  42. #ifndef __UTILITIES__
  43. #include "Utilities.h"
  44. #endif
  45.  
  46.  
  47.  
  48. /*****************************************************************************/
  49.  
  50.  
  51.  
  52. extern short    gPrintPage;        /* Non-zero means we are printing. */
  53.  
  54.  
  55.  
  56. /*****************************************************************************/
  57. /*****************************************************************************/
  58.  
  59.  
  60.  
  61. /* This function adds the application's controls to a window. */
  62.  
  63. #pragma segment Window
  64. OSErr    AppNewWindowControls(FileRecHndl frHndl, WindowPtr window)
  65. {
  66.     WindowPtr    oldPort;
  67.     short        i, mode;
  68.     Rect        brdrRect, viewRect, destRect;
  69.     TEHandle    teHndl, textBox[2];
  70.     Handle        text;
  71.     OSErr        err;
  72.  
  73.     GetPort(&oldPort);
  74.     SetPort(window);
  75.  
  76.     err = noErr;
  77.     for (i = 0; i < 2; ++i) {
  78.         brdrRect = window->portRect;
  79.         --brdrRect.top;
  80.         --brdrRect.left;
  81.         brdrRect.right -= 14;
  82.         brdrRect.bottom = brdrRect.top + (brdrRect.bottom - brdrRect.top + 1) / 2;
  83.         if (i) {
  84.             brdrRect.top = brdrRect.bottom - 1;
  85.             brdrRect.bottom = window->portRect.bottom + 1;
  86.         }
  87.         viewRect = brdrRect;
  88.         InsetRect(&viewRect, 4, 4);
  89.         destRect = viewRect;
  90.         destRect.right -= 2;    /* This fixes a TextEdit problem where the
  91.                                 ** view has to be a little outside the dest on
  92.                                 ** the right, or else characters are clipped. */
  93.  
  94.         mode = i ? (cteVScrollAndGrow) : (cteReadOnly + cteVScroll);
  95.         CTENew(rViewCtl,    /* View ctl ResID used for TextEdit control.       */
  96.                window,        /* Window to hold TERecord.                           */
  97.                &teHndl,        /* Return handle for TERecord.                        */
  98.                &destRect,    /* destRect for TERecord                           */
  99.                &viewRect,    /* viewRect for TERecord                           */
  100.                &brdrRect,    /* Used to frame a border.                           */
  101.                32000,        /* Maximum TextEdit document length.               */
  102.                mode            /* Read-only or read-write, vert scroll, grow box. */
  103.         );
  104.         if (!(textBox[i] = teHndl)) err = memFullErr;
  105.     }
  106.     (*frHndl)->doc.inBox  = textBox[0];
  107.     (*frHndl)->doc.outBox = textBox[1];
  108.  
  109.     if (text = (*frHndl)->doc.textHndl) {
  110.         text = CTESwapText(textBox[1], text, false);
  111.         DisposHandle(text);
  112.         (*frHndl)->doc.textHndl = nil;
  113.     }
  114.  
  115.     SetPort(oldPort);
  116.     return(err);
  117. }
  118.  
  119.  
  120.  
  121. /*****************************************************************************/
  122.  
  123.  
  124.  
  125. /* Image the document into the current port. */
  126.  
  127. #pragma segment Window
  128. void    ImageDocument(FileRecHndl frHndl)
  129. {
  130. #pragma unused (frHndl)
  131.  
  132.     WindowPtr        thePort;
  133.     Rect            rct, theInk;
  134.     TEHandle        te;
  135.     static short    teOffset, teNum;
  136.  
  137.     GetPort(&thePort);
  138.  
  139.     if (!gPrintPage) {                            /* If not printing... */
  140.         DoDrawGrowIcon(thePort, false, false);    /* Draw grow icon without scrollbar lines. */
  141.         DoDrawControls(thePort, false);            /* Draw the controls in the window. */
  142.     }
  143.     else {
  144.         if (gPrintPage == 1) teOffset = teNum = 0;
  145.  
  146.         theInk = thePort->portRect;
  147.         InsetRect(&theInk, 4, 4);        /* Just so no characters get clipped. */
  148.  
  149.         te  = (teNum) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
  150.         rct = theInk;
  151.         CTEPrint(te, &teOffset, &rct);
  152.         if (teOffset == -1) {        /* If TextEdit record is completely printed... */
  153.             teOffset = 0;
  154.             if (teNum) {
  155.                 gPrintPage = 0;        /* Both TextEdit records are printed. */
  156.                 return;                /* We are done. */
  157.             }
  158.             ++teNum;
  159.             te = (*frHndl)->doc.outBox;
  160.             if (rct.bottom != theInk.bottom) {        /* If space left on the page... */
  161.                 rct.top = rct.bottom + 20;
  162.                 rct.bottom = theInk.bottom;
  163.                 if (rct.top < rct.bottom) {
  164.                     CTEPrint(te, &teOffset, &rct);
  165.                     if (teOffset == -1) {
  166.                         gPrintPage = 0;        /* Both TextEdit records are printed. */
  167.                         return;                /* We are done. */
  168.                     }
  169.                 }
  170.             }
  171.         }
  172.     }
  173. }
  174.  
  175.  
  176.  
  177.